#include <cctype>
#include <cstdio>
#define N 1000010
using namespace std;
typedef long long ll;

int n;
int q;
int a[N];
ll sum[N << 2];
ll lazy[N << 2];

inline int read() {
	int ch = getchar(), res = 0;
	bool flag = false;
	while (!isdigit(ch)) {
		if (ch == '-')
			flag = true;
		ch = getchar();
	}
	while (isdigit(ch)) {
		res *= 10, res += ch - '0', ch = getchar();
	}
	return flag ? -res : res;
}

void build(int cur, int l, int r) {
	if (l == r) {
		sum[cur] = a[l];
		return;
	}
	int mid = (l + r) >> 1;
	int ls = cur << 1, rs = cur << 1 | 1;
	build(ls, l, mid);
	build(rs, mid + 1, r);
	sum[cur] = sum[ls] + sum[rs];
}

void add(int cur, int L, int R, int l, int r, ll val) {
	if (L <= l && r <= R) {
		lazy[cur] += val;
		sum[cur] += val * (r - l + 1);
		return;
	}
	int mid = (l + r) >> 1;
	int ls = cur << 1, rs = cur << 1 | 1;
	lazy[ls] += lazy[cur];
	lazy[rs] += lazy[cur];
	sum[ls] += lazy[cur] * (mid - l + 1);
	sum[rs] += lazy[cur] * (r - mid);
	lazy[cur] = 0;
	if (L <= mid) {
		add(ls, L, R, l, mid, val);
	}
	if (R > mid) {
		add(rs, L, R, mid + 1, r, val);
	}
	sum[cur] = sum[ls] + sum[rs];
}

ll query(int cur, int L, int R, int l, int r) {
	if (L <= l && r <= R) {
		return sum[cur];
	}
	ll res = 0;
	int mid = (l + r) >> 1;
	int ls = cur << 1, rs = cur << 1 | 1;
	lazy[ls] += lazy[cur];
	lazy[rs] += lazy[cur];
	sum[ls] += lazy[cur] * (mid - l + 1);
	sum[rs] += lazy[cur] * (r - mid);
	lazy[cur] = 0;
	if (L <= mid) {
		res += query(ls, L, R, l, mid);
	}
	if (R > mid) {
		res += query(rs, L, R, mid + 1, r);
	}
	return res;
}

int main() {
	freopen("segtree.in", "r", stdin);
	freopen("segtree.out", "w", stdout);
	n = read();
	q = read();
	for (int i = 1; i <= n; ++i) {
		a[i] = read();
	}
	build(1, 1, n);
	int opt = 0, a, b;
	ll v;
	while (q--) {
		opt = read();
		if (opt) {
			a = read();
			b = read();
			v = read();
			add(1, a, b, 1, n, v);
		} else {
			a = read();
			b = read();
			printf("%lld\n", query(1, a, b, 1, n));
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}